library(dataRetrieval)# Example: Cache la Poudre River at Mouth (USGS site 06752260)poudre_flow <-readNWISdv(siteNumber ="06752260", # Download data from USGS for site 06752260parameterCd ="00060", # Parameter code 00060 = discharge in cfs)startDate ="2013-01-01", # Set the start dateendDate ="2023-12-31") |># Set the end daterenameNWISColumns() |># Rename columns to standard names (e.g., "Flow", "Date")mutate(Date =yearmonth(Date)) |># Convert daily Date values into a year-month format (e.g., "2023 Jan")group_by(Date) |># Group the data by the new monthly Datesummarise(Flow =mean(Flow)) # Calculate the average daily flow for each month
# Convert to tsibblepoudre_ts <- poudre_flow |>as_tsibble(index = Date)poudre_ts
# A tsibble: 132 x 2 [1M]
Date Flow
<mth> <dbl>
1 2013 Jan 18.1
2 2013 Feb 18.0
3 2013 Mar 8.21
4 2013 Apr 5.94
5 2013 May 333.
6 2013 Jun 300.
7 2013 Jul 75.6
8 2013 Aug 48.8
9 2013 Sep 1085.
10 2013 Oct 146.
# ℹ 122 more rows
2. Plot the Time Series
Code
# Create a static ggplotp <-ggplot(poudre_ts, aes(x = Date, y = Flow)) +geom_line(color ="royalblue") +labs(title ="Monthly Mean Streamflow: Cache la Poudre River (2013–2023)",x ="Date", y ="Flow (cfs)") +theme_minimal()# Interactive version with plotlyggplotly(p)
3. Subseries Plot (Seasonality)
Code
gg_subseries(poudre_ts, Flow)
Interpretation
In the subseries plot, “seasons” are defined as calendar months (Jan–Dec). Each panel shows the variation of stream flow in that specific month across all years (2013–2023).
You can clearly observe a recurring peak in May–June, likely due to snowmelt runoff. This reflects a strong seasonal cycle. The subseries show how much stream flow changes within each month over the years, useful for identifying predictable annual patterns.
The trend component shows long-term variations like multi-year increases or declines in streamflow. The seasonal component shows consistent annual peaks (May–June) and troughs (fall–winter). The remainder captures anomalies such as unexpected high flows from rain events or droughts not explained by the trend or seasonality.